from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-24 14:13:06.059543
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 24, Sep, 2021
Time: 14:13:10
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.3358
Nobs: 424.000 HQIC: -46.8558
Log likelihood: 4680.75 FPE: 3.18670e-21
AIC: -47.1954 Det(Omega_mle): 2.58361e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.429718 0.091951 4.673 0.000
L1.Burgenland 0.106303 0.047599 2.233 0.026
L1.Kärnten -0.114285 0.023823 -4.797 0.000
L1.Niederösterreich 0.156255 0.101885 1.534 0.125
L1.Oberösterreich 0.113725 0.100116 1.136 0.256
L1.Salzburg 0.283908 0.050024 5.675 0.000
L1.Steiermark 0.030937 0.066668 0.464 0.643
L1.Tirol 0.108900 0.052587 2.071 0.038
L1.Vorarlberg -0.102866 0.047086 -2.185 0.029
L1.Wien -0.006140 0.091359 -0.067 0.946
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.009032 0.211018 0.043 0.966
L1.Burgenland -0.048642 0.109234 -0.445 0.656
L1.Kärnten 0.036774 0.054671 0.673 0.501
L1.Niederösterreich -0.211766 0.233816 -0.906 0.365
L1.Oberösterreich 0.485613 0.229756 2.114 0.035
L1.Salzburg 0.306759 0.114801 2.672 0.008
L1.Steiermark 0.107985 0.152997 0.706 0.480
L1.Tirol 0.317067 0.120682 2.627 0.009
L1.Vorarlberg 0.003453 0.108057 0.032 0.975
L1.Wien 0.005186 0.209660 0.025 0.980
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.241468 0.046627 5.179 0.000
L1.Burgenland 0.092012 0.024137 3.812 0.000
L1.Kärnten -0.001867 0.012080 -0.155 0.877
L1.Niederösterreich 0.212237 0.051664 4.108 0.000
L1.Oberösterreich 0.159895 0.050767 3.150 0.002
L1.Salzburg 0.034896 0.025367 1.376 0.169
L1.Steiermark 0.021854 0.033807 0.646 0.518
L1.Tirol 0.068603 0.026666 2.573 0.010
L1.Vorarlberg 0.059020 0.023876 2.472 0.013
L1.Wien 0.113310 0.046327 2.446 0.014
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.183064 0.045674 4.008 0.000
L1.Burgenland 0.048060 0.023644 2.033 0.042
L1.Kärnten -0.006498 0.011833 -0.549 0.583
L1.Niederösterreich 0.141547 0.050609 2.797 0.005
L1.Oberösterreich 0.316374 0.049730 6.362 0.000
L1.Salzburg 0.100825 0.024848 4.058 0.000
L1.Steiermark 0.130572 0.033116 3.943 0.000
L1.Tirol 0.076635 0.026121 2.934 0.003
L1.Vorarlberg 0.055702 0.023389 2.382 0.017
L1.Wien -0.046520 0.045380 -1.025 0.305
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.203885 0.090566 2.251 0.024
L1.Burgenland -0.046447 0.046882 -0.991 0.322
L1.Kärnten -0.034554 0.023464 -1.473 0.141
L1.Niederösterreich 0.110251 0.100350 1.099 0.272
L1.Oberösterreich 0.162513 0.098608 1.648 0.099
L1.Salzburg 0.251465 0.049271 5.104 0.000
L1.Steiermark 0.082646 0.065664 1.259 0.208
L1.Tirol 0.126005 0.051795 2.433 0.015
L1.Vorarlberg 0.115823 0.046376 2.497 0.013
L1.Wien 0.032176 0.089983 0.358 0.721
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.032772 0.069888 0.469 0.639
L1.Burgenland 0.023454 0.036178 0.648 0.517
L1.Kärnten 0.053902 0.018107 2.977 0.003
L1.Niederösterreich 0.209024 0.077439 2.699 0.007
L1.Oberösterreich 0.338099 0.076094 4.443 0.000
L1.Salzburg 0.045384 0.038022 1.194 0.233
L1.Steiermark -0.004324 0.050672 -0.085 0.932
L1.Tirol 0.107705 0.039969 2.695 0.007
L1.Vorarlberg 0.068071 0.035788 1.902 0.057
L1.Wien 0.126817 0.069438 1.826 0.068
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189436 0.085624 2.212 0.027
L1.Burgenland 0.015790 0.044324 0.356 0.722
L1.Kärnten -0.056626 0.022184 -2.553 0.011
L1.Niederösterreich -0.113017 0.094875 -1.191 0.234
L1.Oberösterreich 0.193431 0.093228 2.075 0.038
L1.Salzburg 0.033156 0.046583 0.712 0.477
L1.Steiermark 0.286350 0.062081 4.612 0.000
L1.Tirol 0.488047 0.048969 9.966 0.000
L1.Vorarlberg 0.077513 0.043846 1.768 0.077
L1.Wien -0.111500 0.085073 -1.311 0.190
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158376 0.093555 1.693 0.090
L1.Burgenland -0.011447 0.048429 -0.236 0.813
L1.Kärnten 0.063336 0.024238 2.613 0.009
L1.Niederösterreich 0.194727 0.103663 1.878 0.060
L1.Oberösterreich -0.130141 0.101863 -1.278 0.201
L1.Salzburg 0.236105 0.050897 4.639 0.000
L1.Steiermark 0.151857 0.067832 2.239 0.025
L1.Tirol 0.049703 0.053505 0.929 0.353
L1.Vorarlberg 0.132779 0.047907 2.772 0.006
L1.Wien 0.156974 0.092953 1.689 0.091
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.480746 0.050767 9.470 0.000
L1.Burgenland -0.005827 0.026280 -0.222 0.825
L1.Kärnten -0.009577 0.013153 -0.728 0.467
L1.Niederösterreich 0.203600 0.056252 3.619 0.000
L1.Oberösterreich 0.254075 0.055275 4.597 0.000
L1.Salzburg 0.022348 0.027619 0.809 0.418
L1.Steiermark -0.021739 0.036808 -0.591 0.555
L1.Tirol 0.066469 0.029034 2.289 0.022
L1.Vorarlberg 0.061745 0.025996 2.375 0.018
L1.Wien -0.049256 0.050440 -0.977 0.329
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.022520 0.078465 0.140178 0.131526 0.043094 0.074714 0.001304 0.184436
Kärnten 0.022520 1.000000 -0.043542 0.128860 0.047416 0.070949 0.453162 -0.091126 0.091601
Niederösterreich 0.078465 -0.043542 1.000000 0.282882 0.082348 0.266692 0.019171 0.137439 0.260597
Oberösterreich 0.140178 0.128860 0.282882 1.000000 0.177993 0.289447 0.156983 0.102064 0.137769
Salzburg 0.131526 0.047416 0.082348 0.177993 1.000000 0.124169 0.055405 0.106378 0.052003
Steiermark 0.043094 0.070949 0.266692 0.289447 0.124169 1.000000 0.132089 0.092465 -0.018515
Tirol 0.074714 0.453162 0.019171 0.156983 0.055405 0.132089 1.000000 0.044980 0.118774
Vorarlberg 0.001304 -0.091126 0.137439 0.102064 0.106378 0.092465 0.044980 1.000000 -0.045847
Wien 0.184436 0.091601 0.260597 0.137769 0.052003 -0.018515 0.118774 -0.045847 1.000000